<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

define('SONGCMSROOT','../');
include_once('Admin.php');
$dir = SONGCMSROOT.'uploadfile/';
$dir1 = preg_replace("/[\'\"\\\\\/]/",'',trim($_GET['dir1']));
$dir2 = preg_replace("/[\'\"\\\\\/]/",'',trim($_GET['dir2']));
$path = $dir.(!empty($dir1) ? $dir1.'/' : '').(!empty($dir2) ? $dir2.'/' : '');
if(!file_exists($path)) MsgBox (1,'指定的目录不存在！','-1');
$PageCount = $UpFileManagePage;
$page = is_numeric($_GET['page']) ? $_GET['page'] : 1;

switch ($dir1){
	case 'CKEditor': $Title = "编辑器上传文件"; break;
	case 'Pages': $Title = "页面内容上传文件"; break;
	case 'News': $Title = "新闻上传文件"; break;
	case 'Products': $Title = "产品上传文件"; break;
	case 'GuestBook': $Title = "留言板上传文件"; break;
	case 'Download': $Title = "下载系统上传文件"; break;
	case 'Links': $Title = "友情链接上传文件";break;
	case 'Media': $Title = "视频媒体上传文件";break;
	default : $Title = "上传文件管理"; break;
}

if($_POST['Action']=='Del'){
	$DelFileName = $_POST['DelFileName'];
	if(empty($DelFileName)) {AdminLog(3,1,'在"上传文件管理"中执行批量删除操作(路径:' . $path . ')，结果：操作失败！'); MsgBox (1,'操作失败，请选择要删除的文件！','-1'); }
	foreach ($DelFileName as $i => &$n){
//		$n = iconv("UTF-8","GB2312",$n);
		if(!in_array($n,$NotDelUpFileManage)){
			$dirfiles = $path.$n;
			if(is_file($dirfiles) && @!unlink($dirfiles)){AdminLog(3,1,'在"上传文件管理"中执行批量删除操作(路径:' . $dirfiles . ')，结果：删除失败,权限不足！'); MsgBox (1,'删除文件失败，请确认您是否有相应的操作权限！','-1');}
			if(is_dir($dirfiles) && @!rmdir($dirfiles)){AdminLog(3,1,'在"上传文件管理"中执行删除目录操作(路径:' . $dirfiles . ')，结果：操作失败！'); MsgBox (1,'删除目录失败，该目录下有文件存在或权限不足！','-1');}
		}
	}
	AdminLog(3,1,'在"上传文件管理"中执行批量删除操作(路径:' . $path . ')，结果：操作成功！'); 
	MsgBox (1,'操作成功！','1');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link href="../tools/highslide/highslide.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../tools/highslide/highslide.js" type="text/javascript"></script>
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script type="text/javascript"> 
function CheckAll(form) { //复选框全选/取消
	for (var i=0;i<form.elements.length;i++) { 
		var e = form.elements[i]; 
		if (e.Name != "chkAll"&&e.disabled!=true) 
		e.checked = form.chkAll.checked; 
	} 
} 
hs.graphicsDir = '../tools/highslide/graphics/';
hs.showCredits = false;
hs.outlineType = 'rounded-white';
hs.restoreTitle = '关闭';
</script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
		<td align="right" height="30" style="font-family:宋体;">
<?php
if(!empty($dir2)){
	echo "<img src=\"../images/up.gif\" /> <a href=\"UpFileManage.php\">上传文件管理</a>&nbsp;&gt;&gt;&nbsp;";
	echo "<a href=\"UpFileManage.php?dir1={$dir1}\">{$Title}</a>&nbsp;&gt;&gt;&nbsp;";
	echo "<a href=\"UpFileManage.php?dir1={$dir1}&dir2={$dir2}\">{$dir2}</a>&nbsp;&nbsp;";
} elseif (!empty($dir1)){
	echo "<img src=\"../images/up.gif\" /> <a href=\"UpFileManage.php\">上传文件管理</a>&nbsp;&gt;&gt;&nbsp;";
	echo "<a href=\"UpFileManage.php?dir1={$dir1}\">{$Title}</a>&nbsp;&nbsp;";
} else {
	echo "<img src=\"../images/up.gif\" /> <a href=\"UpFileManage.php\">上传文件管理</a>&nbsp;&nbsp;";
}
?>
	</td></tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form action="UpFileManage.php?dir1=<?php echo $dir1;?>&dir2=<?php echo $dir2;?>&page=<?php echo $page?>" method="post" name="myform">
  <tr>
    <td colspan="5" align="center" class="Main_Title"><?php echo $Title?></td>
  </tr>
  <tr class="odd">
  	<td height="20" align="center" class="b">文件/文件夹名称(预览)</td>
  	<td align="center" class="b"> 文件大小</td>
  	<td align="center" class="b"> 创建时间</td>
  	<td align="center" class="b"> 访问时间</td>
  	<td align="center"><input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value=""></td>
  	</tr>
<?php
$RsCount = (count($Files=MyScandir($path,1)))-2;
$TotalPages = ($RsCount % $PageCount != 0) ? (int)($RsCount/$PageCount+1) : $RsCount/$PageCount; //总页数

for ($i=0; $i<$PageCount; $i++){
	$xi = (($page-1)*$PageCount)+$i;
	if(($RsCount%$PageCount!=0 && $page>=$TotalPages && $i>=$RsCount%$PageCount) || $RsCount==0 || $xi>count($Files)) break;
    $nExtend = strtolower(Extend($FileName = $Files[$xi]));
//	$FileName = iconv("GB2312","UTF-8",$FileName);
	if (!in_array($FileName,$NotDelUpFileManage)){echo '<tr class="odd">';} else {echo '<tr class="odd" id="ippv">';}
	
	if($nExtend=='gif' || $nExtend=='jpg' || $nExtend=='jpeg' || $nExtend=='bmp' || $nExtend=='png'){
		$FileNameText = "<a href=\"{$path}{$FileName}\" onclick=\"return hs.expand(this);\">{$FileName}</a>";
	}else{
		$FileNameText = "<a target=\"_blank\" href=\"{$path}{$FileName}\" title=\"非图片文件，点击下载。\">{$FileName}</a>";
	}
	
	$icon = '../images/filetype/';
	if(is_dir($path.$FileName)){ //目录
		$icon .= 'dir.gif';
		if(empty($dir1)){
			$FileNameText = "<a href=\"UpFileManage.php?dir1={$FileName}\">{$FileName}</a>";
		}else{
			$FileNameText = "<a href=\"UpFileManage.php?dir1={$dir1}&dir2={$FileName}\">{$FileName}</a>";
		}
		$file_size = (FilesSize($path.$FileName,'MB')) . ' MB';
	} else {
		$icon .= "{$nExtend}.gif";
		$file_size = FilesSize($path.$FileName,'KB') . ' KB';
	}	
	if(!is_file($icon)) $icon = "../images/filetype/error.gif"; //不存在的后缀替代图标
	$FileNameText = "<img src=\"{$icon}\" /> {$FileNameText}";
  	echo '<td height="20">' . $FileNameText . '</td>
  	<td align="center">' . $file_size . '</td>
    <td align="center">' . date('Y-m-d H:i:s',@filemtime($path . $FileName)) . '</td>
    <td align="center">' . date('Y-m-d H:i:s',@fileatime($path . $FileName)) . '</td>
    <td align="center"><input type="checkbox" name="DelFileName[]" value="' . $FileName . '"></td>
	</tr>';	
}
?>	
  <tr class="odd">
  	<td height="30" colspan="4" align="center">
<?php
if($RsCount>0){
	echo '共占用空间&nbsp;<font color="#FF0000">' . FilesSize($path,'MB') . '</font> MB&nbsp;|&nbsp;';
	echo pages("dir1={$dir1}&dir2={$dir2}"); 
}else{
	echo '该目录下没有文件！';
}
unset($RsCount,$Files,$PageCount,$i,$FileName,$nExtend,$FileNameText);
?>
</td>
  	<td align="center"><input name="Action" type="hidden" id="Action" value="Del" />  		<input onClick="return confirm('确定删除选定的文件吗？');" type="submit" name="button" id="button" value="删除" /></td>
  </tr>
  </form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
注：1、可能有部分受保护的文件/文件夹做了防删处理！<br />
　　2、您还可以在系统高级参数设定中取消/添加受保护的文件； 
		</td>
	</tr>
</table>  
</body>
</html>
